package operation;

import book.Book;
import book.BookList;

/**
 * Created with IntelliJ IDEA.
 * User:xieChao
 * Date:2022/9/25 11:18
 */
public class DelOperatioin implements IOperation{
    public void work(BookList bookList){
        System.out.println("删除图书！");
        System.out.println("请输入要删除的图书名字：");
        String name = scanner.nextLine();
        int flg = bookList.getUsedSize();
        int index = 0;
        int i = 0;
        for ( i = 0; i < flg; i++) {
            Book book = bookList.getPos(i);
            if(book.getName().equals(name)){
                index = i;
                break;
            }
        }
        if(i>=flg){
            System.out.println("未查询到此书(T-T)");
            return;
        }
        for(int j = index;j<flg-1;j++){
            Book book = bookList.getPos(j+1);
            bookList.setBook(j,book);
        }
        bookList.setBook(flg,null);
        bookList.setUsedSize(flg-1);
        System.out.println("删除成功！！！");
    }
}